package com.goatrock.media.thisway.domain.filter.impl;

import com.goatrock.media.thisway.common.constants.ApplicationConstants;
import com.goatrock.media.thisway.common.model.Title;
import com.goatrock.media.thisway.common.util.StringUtils;
import com.goatrock.media.thisway.domain.filter.TitleFilter;
import java.util.Map;
import org.apache.log4j.Logger;

public class NewMovieFilterImpl implements TitleFilter{
    private String folderName = "New Movies";
    private String name = "New Movies";
    private String description = "Creates a folder with shortcuts to newer movies.  Newer is defined by the input parameter meaning years to go back.";
    private Logger logger = Logger.getLogger(NewMovieFilterImpl.class);

    public String[] execute(Map shortcutParams, Title title) {

        if(title != null && StringUtils.isNotBlank(title.getProductionYear())){
            try{
                int titleYear = Integer.parseInt(title.getProductionYear());
                int startYear = (Integer)shortcutParams.get(ApplicationConstants.CREATE_NEW_MOVIES_START_YEAR);

                if(titleYear >= startYear){
                    return new String[] {folderName};
                }
                return null;
            }catch(Exception e){
                logger.error("inside catch:"+e.getMessage());
                return null;
            }
        }else{
            return null;
        }
    }

    public boolean isExecutable(Map shortcutParams){
        String createNewerMovies = (String)shortcutParams.get(ApplicationConstants.CREATE_NEW_MOVIES);
        if(createNewerMovies != null && createNewerMovies.equalsIgnoreCase(ApplicationConstants.PARAM_USE)){
            return true;
        }
        return false;
    }

    public String getFolderName(){
        return this.folderName;
    }
    public String getName() {
        return this.name;
    }

    public String getDescription() {
        return this.description;
    }

}
